from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-02 14:05:59.989448
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 02, Mar, 2021
Time: 14:06:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4874
Nobs: 218.000 HQIC: -47.3203
Log likelihood: 2525.47 FPE: 1.60029e-21
AIC: -47.8847 Det(Omega_mle): 1.06879e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465480 0.135570 3.433 0.001
L1.Burgenland 0.066595 0.069296 0.961 0.337
L1.Kärnten -0.211142 0.059011 -3.578 0.000
L1.Niederösterreich 0.164643 0.157346 1.046 0.295
L1.Oberösterreich 0.241793 0.140597 1.720 0.085
L1.Salzburg 0.210939 0.074806 2.820 0.005
L1.Steiermark 0.108598 0.100572 1.080 0.280
L1.Tirol 0.124214 0.067460 1.841 0.066
L1.Vorarlberg -0.010635 0.061471 -0.173 0.863
L1.Wien -0.145897 0.131051 -1.113 0.266
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.477554 0.162142 2.945 0.003
L1.Burgenland 0.011957 0.082878 0.144 0.885
L1.Kärnten 0.350268 0.070578 4.963 0.000
L1.Niederösterreich 0.094210 0.188187 0.501 0.617
L1.Oberösterreich -0.116218 0.168155 -0.691 0.489
L1.Salzburg 0.198032 0.089469 2.213 0.027
L1.Steiermark 0.196933 0.120284 1.637 0.102
L1.Tirol 0.143083 0.080683 1.773 0.076
L1.Vorarlberg 0.156157 0.073519 2.124 0.034
L1.Wien -0.498509 0.156737 -3.181 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.309653 0.062690 4.939 0.000
L1.Burgenland 0.096464 0.032044 3.010 0.003
L1.Kärnten -0.019133 0.027288 -0.701 0.483
L1.Niederösterreich 0.084317 0.072760 1.159 0.247
L1.Oberösterreich 0.299765 0.065015 4.611 0.000
L1.Salzburg 0.007735 0.034592 0.224 0.823
L1.Steiermark -0.005733 0.046506 -0.123 0.902
L1.Tirol 0.072437 0.031195 2.322 0.020
L1.Vorarlberg 0.098944 0.028425 3.481 0.000
L1.Wien 0.062273 0.060600 1.028 0.304
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.222708 0.067940 3.278 0.001
L1.Burgenland -0.000804 0.034727 -0.023 0.982
L1.Kärnten 0.018643 0.029573 0.630 0.528
L1.Niederösterreich 0.037091 0.078853 0.470 0.638
L1.Oberösterreich 0.388524 0.070459 5.514 0.000
L1.Salzburg 0.087322 0.037489 2.329 0.020
L1.Steiermark 0.175021 0.050401 3.473 0.001
L1.Tirol 0.043037 0.033807 1.273 0.203
L1.Vorarlberg 0.083734 0.030806 2.718 0.007
L1.Wien -0.055938 0.065675 -0.852 0.394
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.515177 0.134720 3.824 0.000
L1.Burgenland 0.066164 0.068862 0.961 0.337
L1.Kärnten 0.013332 0.058641 0.227 0.820
L1.Niederösterreich -0.014331 0.156360 -0.092 0.927
L1.Oberösterreich 0.133051 0.139716 0.952 0.341
L1.Salzburg 0.063205 0.074337 0.850 0.395
L1.Steiermark 0.105897 0.099941 1.060 0.289
L1.Tirol 0.216739 0.067037 3.233 0.001
L1.Vorarlberg 0.027033 0.061086 0.443 0.658
L1.Wien -0.115940 0.130229 -0.890 0.373
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188800 0.097274 1.941 0.052
L1.Burgenland -0.019324 0.049721 -0.389 0.698
L1.Kärnten -0.007692 0.042342 -0.182 0.856
L1.Niederösterreich 0.056095 0.112899 0.497 0.619
L1.Oberösterreich 0.407401 0.100881 4.038 0.000
L1.Salzburg -0.010471 0.053675 -0.195 0.845
L1.Steiermark -0.013199 0.072162 -0.183 0.855
L1.Tirol 0.175782 0.048404 3.632 0.000
L1.Vorarlberg 0.043550 0.044107 0.987 0.323
L1.Wien 0.186001 0.094031 1.978 0.048
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.232942 0.126515 1.841 0.066
L1.Burgenland 0.031898 0.064667 0.493 0.622
L1.Kärnten -0.034062 0.055070 -0.619 0.536
L1.Niederösterreich -0.030146 0.146836 -0.205 0.837
L1.Oberösterreich -0.075776 0.131206 -0.578 0.564
L1.Salzburg 0.063231 0.069810 0.906 0.365
L1.Steiermark 0.412715 0.093854 4.397 0.000
L1.Tirol 0.447678 0.062954 7.111 0.000
L1.Vorarlberg 0.157885 0.057365 2.752 0.006
L1.Wien -0.204166 0.122297 -1.669 0.095
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125801 0.149990 0.839 0.402
L1.Burgenland 0.022335 0.076667 0.291 0.771
L1.Kärnten -0.070699 0.065288 -1.083 0.279
L1.Niederösterreich 0.192875 0.174083 1.108 0.268
L1.Oberösterreich -0.015195 0.155552 -0.098 0.922
L1.Salzburg 0.254735 0.082763 3.078 0.002
L1.Steiermark 0.142363 0.111269 1.279 0.201
L1.Tirol 0.048740 0.074636 0.653 0.514
L1.Vorarlberg 0.064333 0.068009 0.946 0.344
L1.Wien 0.238188 0.144990 1.643 0.100
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.571603 0.080699 7.083 0.000
L1.Burgenland -0.040294 0.041249 -0.977 0.329
L1.Kärnten -0.014705 0.035127 -0.419 0.675
L1.Niederösterreich -0.004087 0.093661 -0.044 0.965
L1.Oberösterreich 0.311501 0.083691 3.722 0.000
L1.Salzburg 0.020165 0.044529 0.453 0.651
L1.Steiermark -0.003536 0.059866 -0.059 0.953
L1.Tirol 0.073823 0.040156 1.838 0.066
L1.Vorarlberg 0.120932 0.036591 3.305 0.001
L1.Wien -0.028197 0.078008 -0.361 0.718
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.131962 0.042506 0.189435 0.242035 0.061545 0.137872 -0.038787 0.172391
Kärnten 0.131962 1.000000 0.001654 0.196806 0.166091 -0.119835 0.144271 0.010586 0.314267
Niederösterreich 0.042506 0.001654 1.000000 0.275019 0.066610 0.243333 0.168162 0.049211 0.355015
Oberösterreich 0.189435 0.196806 0.275019 1.000000 0.296084 0.279976 0.092360 0.075399 0.128311
Salzburg 0.242035 0.166091 0.066610 0.296084 1.000000 0.133368 0.043142 0.086824 -0.008157
Steiermark 0.061545 -0.119835 0.243333 0.279976 0.133368 1.000000 0.124357 0.117559 -0.103366
Tirol 0.137872 0.144271 0.168162 0.092360 0.043142 0.124357 1.000000 0.177938 0.170484
Vorarlberg -0.038787 0.010586 0.049211 0.075399 0.086824 0.117559 0.177938 1.000000 0.026293
Wien 0.172391 0.314267 0.355015 0.128311 -0.008157 -0.103366 0.170484 0.026293 1.000000